<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>

<html>
<head>

    <%@ include file="/common/common.jsp" %>
    <title>账户激活</title>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/phone.css">
    <link rel="stylesheet" type="text/css" href="${ctx}/css/weui.min.css">
    <!-- <link rel="stylesheet" type="text/css" href="../css/jquery-weui.css"> -->
    <link rel="stylesheet" type="text/css" href="${ctx}/css/demos.css">
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/aui/css/aui.css"/>
    <style type="text/css">
        .refresh_test {
            font-family: PingFangSC-Regular;
            font-size: 14px;
            color: #666666;
            line-height: 21px;
            text-align: center;
        }
        .receivables_error {
            font-family: PingFangSC-Regular;
            font-size: 18px;
            color: #333333;
            text-align: center;
        }
        .receivables_text {
            font-family: PingFangSC-Regular;
            font-size: 15px;
            color: #666666;
            line-height: 30px;
            text-align: right;
        }
        .receivables_amt {
            font-family: PingFangSC-Regular;
            font-size: 20px;
            color: #333333;
            line-height: 21px;
            text-align: right;
        }
        .sonlx {
            font-family: PingFangSC-Regular;
            font-size: 13px;
            color: #666666;
            letter-spacing: 0px;
            text-align: center;
        }
    </style>
</head>

<body>
<section class="aui-content">
    <ul class="aui-list">
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-media" style="width: 4rem;">邀请码</div>
                <div class="aui-list-item-inner  ">
                    <input type="text" id="inviteCode" name="inviteCode" value="" placeholder="请输入您的商户邀请码">
                </div>
            </div>
        </li>
        <li class="aui-list-item">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-media" style="width: 4rem;">手机号</div>
                <div class="aui-list-item-inner  ">
                    <input type="text" id="mobile" name="mobile" value="${mobilephone}" placeholder="请输入您的手机号码">
                </div>
            </div>
        </li>

        <li class="aui-list-item   ">
            <div class="aui-list-item-inner">
                <div class="aui-list-item-media" style="width: 4rem;">验证码</div>
                <div class="aui-list-item-inner  ">
                    <input type="text" id="validationCode" name="validationCode" style="width: 8rem;"
                           placeholder="请输入短信验证码">
                    <input type="button" class="aui-btn aui-btn-warning" id="checkSendOutCode" value="发送验证码" onclick="clickButton(this)"/>
                </div>
            </div>
        </li>
    </ul>
</section>
<section class="aui-content"
         style="margin-top: 14px; padding-left: 20px; padding-right: 20px;">
    <p>
    <div class="aui-btn aui-btn-info  aui-btn-block" onclick="register()">激活</div>
    </p>
</section>

<div class="sonlx" style="margin-top: 10px;">
    <a style="cursor:pointer" onclick="showMessage();">没有邀请码？</a><br>
</div>


<div id="dialogs">
    <div class="js_dialog" id="iosDialog2" style="display: none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__bd" id="DialogMessage"></div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary DeleteDefault">确定</a>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
var $iosDialog2 = $('#iosDialog2');
$('#dialogs').on('click', '.DeleteDefault', function () { //取消按钮事件
    $(this).parents('.js_dialog').fadeOut(200);
});

function showMessage(){
	$("#DialogMessage").html("请找商户索要邀请码！");
    $iosDialog2.fadeIn(200);
}

function clickButton(obj) {
	var inviteCode = $("#inviteCode").val();
	var mobile = $("#mobile").val();
    var obj = $("#checkSendOutCode");
    obj.attr("disabled", "disabled");/* 按钮倒计时 */
	if (mobile.trim().length == 0) {
		$("#DialogMessage").html("请先输入手机号码");
        $iosDialog2.fadeIn(200);
        obj.attr("disabled", false).val("发送验证码");/* 倒计时 */
		$("#mobile").focus();
		return;
	}
    if(!(/^1[34578]\d{9}$/.test(mobile.trim()))){
    	$("#DialogMessage").html("请输入正确的手机号码");
        $iosDialog2.fadeIn(200);
        obj.attr("disabled", false).val("发送验证码");/* 倒计时 */
        return false;
    }
	if (inviteCode.trim().length == 0) {
		$("#DialogMessage").html("请填写邀请码");
        $iosDialog2.fadeIn(200);
        obj.attr("disabled", false).val("发送验证码");/* 倒计时 */
        return;
	}
    $.ajax({
        type:"POST",
        url:"../auth/getActivateValidCode",
        data:{mobile:mobile,inviteCode:inviteCode},
        dataType:"json",
        success:function(result){
            if(result.code==0){
                getValidCode();
            }else{
            	$("#DialogMessage").html(result.msg);
                $iosDialog2.fadeIn(200);
                obj.attr("disabled", false).val("发送验证码");/* 倒计时 */
            }
        },error: function (data) {
            obj.attr("disabled", false).val("发送验证码");/* 倒计时 */
        }
    });
}

function getValidCode(){
    var obj = $("#checkSendOutCode");
    var time = 60;
    var set = setInterval(function() {
        obj.val(--time + "(s)");
    }, 1000);/* 等待时间 */
    setTimeout(function() {
        obj.attr("disabled", false).val("重新获取验证码");/* 倒计时 */
        clearInterval(set);
    }, 60000);
}
/**
 * 注册
 */
function register(){
	var inviteCode = $("#inviteCode").val();
	var mobile = $("#mobile").val();
	var validationCode = $("#validationCode").val();
	if (inviteCode.trim().length == 0) {
		$("#DialogMessage").html("请填写邀请码");
        $iosDialog2.fadeIn(200);
		return;
	}
	if (mobile.trim().length == 0) {
		$("#DialogMessage").html("请填写手机号码");
        $iosDialog2.fadeIn(200);
		return;
	}
	if(!(/^1[34578]\d{9}$/.test(mobile.trim()))){
    	$("#DialogMessage").html("请输入正确的手机号码");
        $iosDialog2.fadeIn(200);
        return false;
    }
	if (validationCode.trim().length == 0) {
		$("#DialogMessage").html("请输入验证码");
        $iosDialog2.fadeIn(200);
		return;
	}
	$.ajax({
		type : "POST",
		url :"../auth/activate",
		data : {
			inviteCode : inviteCode,
			validationCode : validationCode,
			mobile : mobile
		},
		dataType : "json",
		success : function(result) {
			$("#DialogMessage").html(result.msg);
	        $iosDialog2.fadeIn(200);
			if(result.code!="500"){
				//location.href="../auth/logout";
				window.location.href="../auth/loginSuccess";
			}
		}
	});
}
</script>
</body>
</html>


 